home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: const pointer confusion...
- Date: 25 Mar 1996 06:23:37 -0600
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4j6389$3iq@solutions.solon.com>
- References: <4j06gm$7oa@solutions.solon.com> <4j41io$nma@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4j41io$nma@solutions.solon.com>,
- Huayong Yang <yang@math.umass.edu> wrote:
- >
- >const int *p and int const *p are the same: a pointer to const integer;
- >int * const p means a const pointer to integer. A little program to
- >verify it:
-
- This is true. The grammar of the C language allows type specifiers, type
- qualifers and storage class specifiers to appear in any order in the syntactic
- unit ``declaration-specifiers''. Thus,
-
- const int i;
-
- and
- int const i;
-
- are essentially the same declaration. It's probably good style to not use any
- old arbitrary order, but stick to putting the storage class first (if any),
- followed by the const or volatile qualifier, followed by the type.
-
- In the case of declarations, there is no ambiguity, since in a declarator only
- the '*' keyword can introduce a type qualifier list, and the '*' keyword cannot
- appear in a declaration specifier list.
-
- So in ``int const i'', the const must belong with the ``int'', since ``const
- i'' is not a valid declarator. On the other hand, ``int * const i'' makes the
- const belong with the *, since the ``direct-declarator'' i is preceded by an
- optional ``pointer'', a syntactic unit which can generate a '*' followed by an
- optional list of type qualifiers followed an optional recursive instance of
- ``pointer''.
- --
-